#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1000000000;
const ldb pi = fabsl(atan2(0.0, -1.0));
using namespace std;

int n, m;

int a[100][100];
int dp[78][78][78][78];
short int was[78][78][78][78];
int s[78][78];

int calced = 0;

int Load()
{
	scanf("%d%d", &n, &m);
	if (n == 0 && m == 0) return 0;
	int i, j;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= m; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	return 1;
}

inline int f(int i, int j, int h, int w)
{
	if (h == 0 || w == 0) return INF;
	if (i <= 0 || j <= 0) return INF;
	if (was[i][j][h][w] == calced) return dp[i][j][h][w];
	was[i][j][h][w] = calced;
	dp[i][j][h][w] = INF;
	dp[i][j][h][w] = min(dp[i][j][h][w], 
	min(f(i - 1, j, h - 1, w), 
	min(f(i, j - 1, h, w - 1),
	min(f(i, j, h, w - 1),
	min(f(i, j, h - 1, w),
	s[i][j] - s[i - h][j] - s[i][j - w] + s[i - h][j - w]
	)))));
	return dp[i][j][h][w];
}

void Solve()
{
	int i, j, w, h;
	calced++;
	for (i = 1; i <= n; i++)
		for (j = 1; j <= m; j++)
			s[i][j] = a[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
	int res = -INF;
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= m; j++)
		{
			for (w = 3; w <= j; w++)
			{
				for (h = 3; h <= i; h++)
				{
				//	cerr << i << " " << j << " " << h << " " << w << " " << s[i][j] - s[i - h][j] - s[i][j - w] + s[i - h][j - w] << " " <<   f(i - 1, j - 1, h - 2, w - 2) << "\n";
					res = max(res, s[i][j] - s[i - h][j] - s[i][j - w] + s[i - h][j - w] - f(i - 1, j - 1, h - 2, w - 2));
				}
			}
		}
	}
	cout << res << "\n";
}

#define file "omax"
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	#endif
	while (Load()) Solve();
	return 0;
}